//
//  CZPushBottomView.swift
//  GZWeibo007
//
//  Created by mac on 15/12/24.
//  Copyright © 2015年 Apple. All rights reserved.
//

import UIKit

// 按钮点击事件协议
protocol CZPushBottomViewDelegate: NSObjectProtocol
{
    // 点击转发
    func pushBottomViewForwardButtonDidClick(btn: UIButton)
    
    // 点击评论
    func pushBottomViewCommentButtonDidClick(btn: UIButton)
    
    // 点击赞
    func pushBottomViewLikeButtonDidClick(btn: UIButton)
    
}


class CZPushBottomView: UIView
{
    
    // MARK: - 设置代理属性
    weak var delegate: CZPushBottomViewDelegate?

    required init?(coder aDecoder: NSCoder) {
        fatalError("init(coder:) has not been implemented")
    }
    
    override init(frame: CGRect) {
        super.init(frame: frame)
        
        // 准备UI
        prepareUI()
        
        backgroundColor = UIColor(white: 0.96, alpha: 1)
    }

    
    private func prepareUI()
    {
        // 添加子控件
        addSubview(forwardButton)
        addSubview(commentButton)
        addSubview(likeButton)
        addSubview(separatorFirstView)
        addSubview(separatorSecondView)
        
        
        // 添加约束
        // 三个按钮对父控件进行平铺
        self.ff_HorizontalTile([forwardButton,commentButton,likeButton], insets: UIEdgeInsetsZero)
        
        // 分割线1
        separatorFirstView.ff_AlignHorizontal(type: ff_AlignType.CenterRight, referView: forwardButton, size: nil)
        
        // 分割线2
        separatorSecondView.ff_AlignHorizontal(type: ff_AlignType.CenterRight, referView: commentButton, size: nil)
        
    }
    
    
    // MARK: - 懒加载子控件
    // 转发
    private lazy var forwardButton: UIButton =
    {
        let forwardButton = UIButton(imageName: "timeline_icon_retweet", fontSize: 11, title: "转发")
        
        // 添加点击事件
        forwardButton.addTarget(self, action: "forwardButtonDidClick:", forControlEvents: UIControlEvents.TouchUpInside)
        
        
        return forwardButton
        
    }()
    
    
    // 评论
    private lazy var commentButton: UIButton =
    {
        let commentButton = UIButton(imageName: "timeline_icon_comment", fontSize: 11, title: "评论")
        
        // 添加点击事件
        commentButton.addTarget(self, action: "commentButtonDidClick:", forControlEvents: UIControlEvents.TouchUpInside)
        
        
        return commentButton
    }()
    
    // 赞
     private lazy var likeButton: UIButton =
    {
        let likeButton = UIButton(imageName: "timeline_icon_unlike", fontSize: 11, title: "赞")
        
        
        // 添加点击事件
        likeButton.addTarget(self, action: "likeButtonDidClick:", forControlEvents: UIControlEvents.TouchUpInside)

        
        return likeButton
        
    }()
    
    // 分割线1
    private lazy var separatorFirstView: UIImageView = UIImageView(image: UIImage(named: "timeline_card_bottom_line_highlighted"))
    
    // 分割线2
    private lazy var separatorSecondView: UIImageView = UIImageView(image: UIImage(named: "timeline_card_bottom_line_highlighted"))
    
    // MARK: - 点击事件
    // 点击转发
    func forwardButtonDidClick(btn: UIButton)
    {
        delegate?.pushBottomViewForwardButtonDidClick(btn)
    }
    
    // 点击评论
    func commentButtonDidClick(btn: UIButton)
    {
        delegate?.pushBottomViewCommentButtonDidClick(btn)
    }
    
    // 点击赞
    func likeButtonDidClick(btn: UIButton)
    {
        delegate?.pushBottomViewLikeButtonDidClick(btn)
    }

}
